package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketFeedback;
import com.cskaoyan.market.db.domain.MarketFeedbackExample;
import com.cskaoyan.market.db.domain.MarketSearchHistory;
import com.cskaoyan.market.db.domain.MarketSearchHistoryExample;
import com.cskaoyan.market.db.mapper.MarketFeedbackMapper;
import com.cskaoyan.market.db.mapper.MarketSearchHistoryMapper;
import com.cskaoyan.market.service.AdminFeedbackService;
import com.cskaoyan.market.util.MybatisUtil;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminFeedbackServiceImpl implements AdminFeedbackService {


    @Override
    public List<MarketFeedback> list(String page, String limit, String username, String id, String sort, String order) {
        SqlSession session = MybatisUtil.getSession();
        MarketFeedbackMapper mapper = session.getMapper(MarketFeedbackMapper.class);
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();
        MarketFeedbackExample.Criteria criteria = marketFeedbackExample.createCriteria();
        if(!StringUtils.isEmpty(username))
            criteria.andUsernameEqualTo("%"+username+"%");
        if(!StringUtils.isEmpty(id))
            criteria.andIdEqualTo(Integer.parseInt(id));
        marketFeedbackExample.setOrderByClause(sort + " " + order);
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));
        List<MarketFeedback> marketFeedbacks = mapper.selectByExample(marketFeedbackExample);
        session.commit();
        session.close();
        return marketFeedbacks;
    }
}
